package com.hubei.car.utils;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * 时间转换器
 * @author luokangtao
 * @create 2019-08-14 14:58
 */
public class DateUtil {

    /**
     * localdatetime转换字符串
     * @param localDateTime
     * @return
     */
    public static String  localDateTimeToString(LocalDateTime localDateTime){
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return df.format(localDateTime);
    }

    /**
     * date转换字符串
     * @param date
     * @return
     */
    public static String  dateToString(Date date){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        return simpleDateFormat.format(date);
    }

    /**
     * timestamp 转换字符串
     * @param timestamp
     * @return
     */
    public static String  timestampToString(Timestamp timestamp){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return simpleDateFormat.format(timestamp);
    }
}
